package com.projectexercise.book.model;

import com.projectexercise.book.enums.ResponseStatus;
import lombok.Data;

@Data
public class Result<T> {
    private ResponseStatus code;
    private String errorMess;
    private T data;

    public Result() {
    }

    public Result(ResponseStatus code, String errorMess, T data) {
        this.code = code;
        this.errorMess = errorMess;
        this.data = data;
    }
    public static <T> Result<T> success(T data){
        Result<T> result = new Result<>();
        result.setCode(ResponseStatus.SUCCESS);
        result.setData(data);
        return result;
    }
    public static <T> Result<T> noLogin(){
        return new Result<>(ResponseStatus.NO_LOGIN,"用户未登录",null);
    }

    public static <T> Result<T> fail(String mess){
        return new Result<>(ResponseStatus.FAIL, mess,null);
    }
}
